/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package snippet.theory7;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 *
 * @author hoang.pt
 */
public class GroupDemo {

    public static void main(String[] args) {

        String text1 = "papa";
        String text2 = "pass";

        String regex = "([a-z][a-z])(\1$)";

        //
        Pattern pattern = Pattern.compile(regex);
        Matcher matcher1 = pattern.matcher(text1);
        Matcher matcher2 = pattern.matcher(text2);

        while (matcher1.find()) {
            System.out.println(matcher1.start());
            System.out.println(matcher1.end());
        }

        while (matcher2.find()) {
            System.out.println(matcher2.start());
            System.out.println(matcher2.end());

        }



    }
}
